package org.javacore.StreamsTutorial;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;

/**
 * Created by IntelliJ IDEA.
 * User: Fan
 * Date: 2018/6/30
 * Time: 16:20
 */
public class FileTest {

    public static void main(String[] args) {
        fileReader();

    }

    //Stream rows from CSV file and count
    public static void fileCount(){
        try {
            Stream<String> rows1 = Files.lines(Paths.get("D:\\测试文件\\新建文本文档.txt"));
            int rowCount = (int) rows1.map(x->x.split(",")).filter(x->x.length==3).count();
            System.out.println(rowCount + "====rows");
            rows1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //使用流读取File文件内容
    public static void fileReader(){
        try {
            Stream<String> row = Files.lines(Paths.get("D:\\测试文件\\新建文本文档.txt"));
            row.forEach(
                s -> {
                    System.out.println("========row== "+s);
                }
            );
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
